#pragma once

#include "../header/FileSystem.h"

static void Print_bitmap(FileSystem *fs) {
    DEBUG_BEGIN("print bitmap")
    short *bitmap = (short *) fs->blockBitmap;
    for (int i = 0; i < BLOCK_SIZE / 4; ++i) {
        printf("%.4hx ", bitmap[i]);
    }
    putchar('\n');
    DEBUG_END
}

static void Print_inodeList(FileSystem *fs) {
    DEBUG_BEGIN("print inode list")
        Inode *inodes = fs->InodeList;
        for (int i = 0; i < INODE_LIST_SIZE; ++i) {
            if (inodes[i].status != 0) {
                Inode_print(inodes + i);
            }
        }
    DEBUG_END
}

static void Print_FCBList(FileSystem *fs) {
    DEBUG_BEGIN("print fcb list")
        FCB *fcbList = fs->FCBList;
        for (int i = 0; i < FCB_LIST_SIZE; ++i) {
            if (fcbList[i].name[0] != '\0') {
                printf("%s %d\n", fcbList[i].name, fcbList[i].inodeNumber);
            }
        }
    DEBUG_END
}

static void PRI_dfsDir(FileSystem *fs, FCB *currentFCB, Inode *currentInode) {
    if (currentInode->parent == NOTHING) {
        return;
    }
    FCB *nextFCB = fs->FCBList + currentInode->parent;
    Inode *nextInode = fs->InodeList + nextFCB->inodeNumber;
    PRI_dfsDir(fs, nextFCB, nextInode);
    printf("/%s", currentFCB->name);
}

static void Print_currentDirectory(FileSystem *fs, CurrentStatus *currentStatus) {
    FCB *currentFCB = fs->FCBList + currentStatus->currentDirectory;
    Inode *currentInode = fs->InodeList + currentFCB->inodeNumber;
    BROWN
    if (currentStatus->currentDirectory == 0) {
        printf("/");
    } else {
        PRI_dfsDir(fs, currentFCB, currentInode);
    }
    printf("> ");
    COLOR_RESET
}

static void Print_CreateFileParams(CreateFileParams *params) {
    DEBUG_BEGIN("print params")
        printf("fromRoot:%d fileSize:%dKB pathSize:%d\n",
               params->pathInfo->fromRoot, params->fileSize, params->pathInfo->pathSize);
        for (int i = 0; i < params->pathInfo->pathSize; ++i) {
            puts(params->pathInfo->path[i]);
        }
    DEBUG_END
}